package com.example.transformpage.NoHttp.controlQueue;


import android.os.SystemClock;

import com.baselibrary.libs.Utils.log.LogUtils;
import com.example.transformpage.NoHttp.queue.Request;
import com.example.transformpage.NoHttp.queue.TaskExecutor;
import com.example.transformpage.NoHttp.queue.YolandaLinkedQueue;
import com.example.transformpage.NoHttp.task.NetworkInterface_plan;


/**
 * Created by Administrator 于萌萌
 * 创建日期: 17:44 . 2016年12月28日
 * 描述:
 * <p>
 * <p>
 * 备注:
 */

public class ControlQueue extends YolandaLinkedQueue<Request,Integer,Integer,DownTimer> {

    static ControlQueue sControlQueue;




    public ControlQueue(int poolSize) {
        super(poolSize);
    }
    //子线程
    @Override
    public void getData(Request request, TaskExecutor<Request, Integer, Integer, DownTimer> taskExecutor, YolandaLinkedQueue<Request, Integer, Integer, DownTimer> queue) {
        if (null!=CancelTag){

            if (null!=request.getCancelTagObject()&&CancelTag==request.getCancelTagObject()){
                    return;
            }
        }


        long timer = request.getTimer();
        int time = 1000;
        while (time>0){
            if (dump){
                return;
            }
            LogUtils.i("我现在的数字是"+"w当前id"+request.getId()+"\t"+time);
            time-=100;
            SystemClock.sleep(98);
        }

        timer-=1000;
        LogUtils.i("当前线程计数"+"当前id"+request.getId()+"当前时间"+timer);

        if (dump){
            return;
        }
        if (timer<=0) {
            timer = 0;
            queue.onResult(new DownTimer(request.getId(),timer));
        } else{

            queue.onResult(new DownTimer(request.getId(),timer));
        }
        }

    @Override
    public void getResult(DownTimer downTimer) {
        mCallBack.onResult(downTimer);
    }

    @Override
    public void getUpData(Integer integer) {
        mCallBack.onUpData(integer);
    }




    NetworkInterface_plan mCallBack;

    public static ControlQueue getControlQueue(int poolSize){
        if (sControlQueue==null)
            return sControlQueue = new ControlQueue(poolSize);
         return sControlQueue;
        }
    public void setCallBack(NetworkInterface_plan<DownTimer,Integer> mCallBack){
        this.mCallBack= mCallBack;
    }



    @Override
    public void getParam(Integer integer) {
       // mCallBack.onParm(integer);

    }


}




